var express = require("express");
var router = express.Router();

let { RunModel } = require("../model/model");
/* GET users listing. */

router.get("/list", async (req, res) => {
  let data = await RunModel.find();
  res.send({ code: 200, data });
});
router.post("/add", async (req, res) => {
  let body = req.body;
  let result = await RunModel.find({ date: body.date });
  if (result.length > 0) {
    let update = result[0];
    update.daykm = body.daykm + update.daykm;
    await update.save();
    res.send({ code: 200 });
  } else {
    await RunModel.create(req.body);
    res.send({ code: 200 });
  }
});

module.exports = router;
